package com.jaay.dao;

import com.jaay.pojo.Order;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.aggregation.LookupOperation;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class OrderDao extends BaseDao<Order, Long> {


    public List<Order> queryOrderAndProductList(){
        LookupOperation lookupOperation = LookupOperation.newLookup()
                .from("product").
                localField("orderNo")
                .foreignField("orderNo")
                .as("productList");

        Aggregation aggregation = Aggregation.newAggregation(lookupOperation);
        AggregationResults<Order> results = this.aggregate(aggregation,"order");
        return results.getMappedResults();
    }


}
